//
//  PrinterConnectSwitchTCell.swift
//  imember_printer
//
//  Created by feibi on 2022/1/17.
//

import UIKit

class PrinterConnectSwitchTCell: BaseTableViewCell {
    // MARK: - Property
    var disconnectBtnClick: (() -> Void)?
    var title: String? {
        didSet {
            titleLabel.text = title
        }
    }
    
    var disconnectBtnHidden: Bool? {
        didSet {
            disconnectBtn.isHidden = disconnectBtnHidden ?? false
        }
    }
    
    // MARK: - Private_M
    override func configUI() {
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints {
            $0.top.bottom.equalToSuperview()
            $0.left.equalToSuperview().offset(16)
        }
        
        contentView.addSubview(disconnectBtn)
        disconnectBtn.snp.makeConstraints {
            $0.right.equalToSuperview().offset(-16)
            $0.top.bottom.equalToSuperview()
        }
    }
    
    @objc private func disconnectBtnTap() {
        if let disconnectBtnClick = disconnectBtnClick {
            disconnectBtnClick()
        }
    }
    
    // MARK: - Getter
    private lazy var titleLabel: UILabel = {
        let tl = UILabel()
        tl.text = "當前設備"
        return tl
    }()
    
    private lazy var disconnectBtn: UIButton = {
        let db = UIButton(type: .custom)
        db.setTitle("斷開", for: .normal)
        db.setTitleColor(.red, for: .normal)
        db.addTarget(self, action: #selector(disconnectBtnTap), for: .touchUpInside)
        return db
    }()
}
